home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # padd - package add script
- # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
- # released under gpl.
- #
- # $1: pathname of package to add
- # ex: padd /usr/src/RedmondLinux/SRPMS/mypackage-1.1-1.src.rpm
- # ex: padd mypackage-1.1-1.src.rpm
- #
- # opts: -q: quiet [don't print status messages]
- # -v: verbose
- # -l: language to add to [default: all languages]
-
- # BUG: use getopts instead
- LANG=
- ERROR=0
-
- if [ "n$1" = "n-q" ]; then # -q
- QUIET="-q"
- shift
- fi
-
- if [ "n$1" = "n-v" ]; then # -v
- VERBOSE="-v"
- shift
- fi
-
- if [ "n$1" = "n-l" ]; then # -l
- LANG="$2"
- shift
- shift
- fi
-
-
- # constants and vars
-
- RL_ROOT=/opt/redmondlinux
- BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
- BUILD_NUM=`cat $BUILD_NUM_FILE`
-
- BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
-
- cd $BUILD_ROOT
- LANG_TO_PROCESS=`echo ${LANG}*`
- cd -
- [ $VERBOSE ] && echo Languages to process: $LANG_TO_PROCESS
-
- while [ $# -ge 1 ]; do # for each file to add
-
- if [ ! -r "$1" ]; then # file doesn't exist
- echo `basename $0`: can\'t find \"$1\" >&2
- shift ; continue
- fi
-
- for lang in $LANG_TO_PROCESS; do # for each lang
- [ $VERBOSE ] && echo checking $lang
-
- PAT_FILE=$BUILD_ROOT/$lang/rl/data/regex_patterns.txt
-
- #
- #
- # find pattern to match
-
- { while read LINE; do
-
- if [ "`echo $LINE | cut -c 1`" = "#" ] || [ "$LINE" = "" ]; then
- # comment or blank line, continue
- continue
- fi
-
- # separate the regexp and the directory
- REGEX=`echo $LINE | cut -f 1 -d \ `
- DIR=`echo $LINE | cut -f 2 -d \ `
- [ $VERBOSE ] && echo $REGEX = $DIR
-
- # test for match
- basename "$1" | grep -q -e $REGEX
- MATCH=$[ ! $? ]
- [ $VERBOSE ] && echo match = $MATCH
-
- [ $MATCH -eq 1 ] && break
-
- done } < $PAT_FILE # find pattern to match
-
- # match?
- if [ $MATCH -eq 1 ]; then
- # yes, perform update
- [ $VERBOSE ] && echo fadd $QUIET -l $lang "$1" $DIR
- # we can specify a file is not to be added by making DIR=/dev/null
- [ "$DIR" = "/dev/null" ] && echo /dev/null && shift && continue 2
- fadd $QUIET -l $lang "$1" $DIR
-
- # successful?
- RETURN=$?
- # no, continue
- [ $RETURN -gt 0 ] && continue
- # yes, update pkgs.db
-
- BASENAME=`basename "$1"`
- UPDATED_FILE="$BUILD_ROOT/$lang/$DIR/$BASENAME"
-
- # source rpm?
-
- if [ "$BASENAME" = `basename "$1" .src.rpm`.src.rpm ]; then
- echo source rpm, not updating && continue
- fi
-
- # get needed info
-
- PACK_SIZE=`ls -l $UPDATED_FILE | tr -s \ | cut -d \ -f 5` # packed size
- eval `rpmextr --shell $UPDATED_FILE` # unpacked size, package name, version, release
- PKGS_DB=$BUILD_ROOT/$lang/rl/data/pkgs.db
- DB_LINE=`grep \[A-Z\]*:$PKG_NAME:.* < $PKGS_DB` # get line from DB
-
- # no line? exit
- [ "$DB_LINE" = "" ] && continue
-
- perl -pi -e \
- "s/:$PKG_NAME:(.*?:.*?):.*?:(.*?):.*?:.*::/:$PKG_NAME:\$1:$PKG_SIZE:\$2:$PACK_SIZE:$PKG_VERS-$PKG_RELEASE::/g" $PKGS_DB
-
- DB_LINE=`grep \[A-Z\]*:$PKG_NAME:.* < $PKGS_DB`
- echo $DB_LINE
- continue
-
- fi
-
- [ $QUIET ] || echo match not found. no add performed.
-
- done # for each lang
-
- shift
-
- done # for each file to add
-